package cn.jlonely.xyhx.admin.controller;

import cn.jlonely.xyhx.pojo.User;
import cn.jlonely.xyhx.admin.service.UserService;
import cn.jlonely.xyhx.utils.PageResult;
import cn.jlonely.xyhx.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 分页获取用户信息
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/pageUser")
    public Result getUserInfo(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize,String name){
        PageResult<User> user = userService.pageUser(page,pageSize,name);
        return Result.success(user);
    }

    /**
     * 更新用户状态
     * @param id
     * @param userStatus
     * @return
     */

    @PostMapping("/updateUserStatus")
    public Result updateUserStatus(@RequestParam("id") Integer id,@RequestParam("userStatus") Integer userStatus){
        userService.updateUserStatus(id,userStatus);
        return Result.success();
    }

    /**
     * c重置密码
     * @param id
     * @return
     */
    @PutMapping("/resetUserPassword")
    public Result resetUserPassword(@RequestParam("id") Integer id) throws Exception {
        userService.resetUserPassword(id);
        return Result.success();
    }

}
